package sh.base.aop;

import lombok.Setter;
import org.aopalliance.intercept.MethodInterceptor;

/**
 * 代理的统一入口，支持jdk和cglib
 * todo 如果一个对象有两个不同的拦截处理方法如何做？先做一个的
 * @author lqq
 * @date 2019/2/23
 */
public class ProxyManager {

    @Setter
    private MethodInterceptor methodInterceptor;

    /** 源对象信息 */
    @Setter
    private TargetSource targetSource;

    private AopProxy aopProxy;

    /**
     * 返回带有拦截功能的代理对象，根据情况返回cglib或者jdk的代理
     * @return
     */
    public Object getProxy(){
        if(targetSource.getInterfaces() != null){
            //jdk方式
            aopProxy = new JdkProxy(this.targetSource, methodInterceptor);
        }else{
            aopProxy = new CglibProxy(this.targetSource, methodInterceptor);
        }
        return aopProxy.getProxy();
    }

}
